package com.videoaggre.zcl.ui.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.videoaggre.zcl.helper.OnCheckBean

abstract class BaseSignCheckAdapter<VH : RecyclerView.ViewHolder, B : OnCheckBean> : BaseRecyclerAdapter<VH, B>() {
    fun getCheck(): B {
        for (item in datas) {
            if (item.check()) return item
        }
        return getItem(0)
    }

    fun chengeCheck(position: Int) {
        datas.forEachIndexed { index, checkBean ->
            if (position != index && checkBean.check()) {
                checkBean.changeCheck(false)
                notifyItemChanged(index)
            }
        }
        if (position in 0 until itemCount) {
            val item = getItem(position)
            if (!item.check()) {
                item.changeCheck(true)
                notifyItemChanged(position)
            }
        }
    }

    // 单选
    override fun subOnClickAdapter(v: View, position: Int) {
        chengeCheck(position)
    }
}